package com.lms.common.pure.entity;

import com.alibaba.fastjson2.annotation.JSONField;

import java.io.Serializable;
import java.util.List;

public interface ITreeNode<I extends Serializable> {
    void setId(I id);
    I getId();
    void setName(String name);
    String getName();

    void setType(String type);
    String getType();

    default void setParent(ITreeNode<?> parent) {

    }

    @JSONField(serialize = false)
    default ITreeNode<?> getParent() {
        return null;
    }

    default void setVirtual(boolean virtual) {

    }

    @JSONField(serialize = false)
    default boolean isVirtual() {
        return false;
    }

    default <N extends ITreeNode<?>>void addChild(N child) {
        if (this.getChildren() != null) {
            this.getChildren().add(child);
            child.setParent(this);
        }
    }
    default <N extends ITreeNode<?>> List<N> getChildren() {
        return null;
    }
    default boolean hasChild() {
        if (this.getChildren() == null) return false;
        return !this.getChildren().isEmpty();
    }
}
